package com.doyens.gmall.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.doyens.gmall.common.result.Result;
import com.doyens.gmall.model.product.BaseAttrInfo;
import com.doyens.gmall.model.product.BaseAttrValue;
import com.doyens.gmall.model.product.BaseTrademark;
import com.doyens.gmall.product.service.ManageService;
import com.doyens.gmall.product.service.impl.TrademarkServiceimpl;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product/baseTrademark")
@Api("品牌基础属性接口")
public class TrademarkController {
    @Autowired
    TrademarkServiceimpl tsi;//继承了baomidou的Serviceimpl有很多方法


    @GetMapping("{page}/{limit}") //分页查询
    public Result getTrademarkPage(@PathVariable Long page,@PathVariable Long limit){

        Page<BaseTrademark> baseTrademarkPage = new Page<>(page,limit);
        return Result.ok(tsi.page(baseTrademarkPage,null));
    }

    @PostMapping("save") //添加
    public Result saveTrademarkPage(@RequestBody BaseTrademark baseTrademark){
        tsi.save(baseTrademark);
        return Result.ok();
    }

    @GetMapping("get/{id}") //根据id查询
    public Result<BaseTrademark> findAttrValueListByid(@PathVariable("id")Long Id){
        BaseTrademark byId = tsi.getById(Id);
        return Result.ok(byId);
    }

    @DeleteMapping("remove/{id}") //删除
    public Result removeTrademarkByid(@PathVariable Long id){
        tsi.remove(new QueryWrapper<BaseTrademark>().eq("id",id));
        return Result.ok();
    }
    @PutMapping("update") //修改
    public Result updateTrademark(@RequestBody BaseTrademark baseTrademark){
       tsi.updateById(baseTrademark);
        return Result.ok();
    }

    @GetMapping("getTrademarkList") //获取所有品牌
    public Result<List<BaseTrademark>> getTrademarkList(){
        return Result.ok(tsi.list(null));
    }
}
